-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Break up Effects.js #672
Break up Effects.js #672
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love it! Thanks for diving into this! I know the goal of this PR was to minimize code changes so I'm good with this as is, but I also had a few other follow-ups in mind:
- Since we're creating new files, can we go ahead and use ES6 import/exports? e.g.
export default function(p5...)
instead ofmodule.exports =
andimport
instead ofrequire
? - Thoughts on creating classes for each effect? It would be a little more verbose, but could make parsing the code a little easier? e.g.
class BloomingPetals {
constructor(p5, getCurrentPalette, colorFromPalette) {
...
}
init() { ... }
}
then in Effects.js, this.blooming_petals = new BloomingPetals(p5, getCurrentPalette, colorFromPalette)
@sanchitmalhotra126 , could you explain why this would be easier to parse? |
It's just more modern syntax - the current format seems like it's the older pre-ES6 version of classes where you'd write it as a function that returns an object, but still use the Also, thinking ahead to if we were to eventually start using TypeScript in this package, we could declare an interface/abstract class that these classes implement/inherit from. These could define the signatures for some common functions like |
Gotcha - so it would be easier for humans to read.
Cool - thanks for the explanation! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love how much easier it is to 'parse' through the Effects.js
file.
Looking forward to seeing follow-up steps as well (including @sanchitmalhotra126 's suggestions). Thanks for getting the much-needed refactoring effort started in this repo!
@sanchitmalhotra126 agree re: classes, was just easier to copy/paste if I stuck to the existing older syntax. Re: ES6 import/export, I played with using Both of these do feel like work items that could be picked up as standalone follow-ups. |
Oh this is interesting re: Babel config when using
https://github.com/code-dot-org/code-dot-org/blob/staging-next/apps/babel.config.json#L1-L2 |
Just a note that our |
A first step in refactoring our quite large Effects.js file (ie, the code that renders the details of each foreground/background). I put each effect into its own file, and organize into background and foreground effects folders.
I tried to make the changes in this PR as minimal as possible (ie, only moving code between files and including function arguments where needed), but a couple next steps I'm thinking about:
/effects/effectName
Testing story
I manually tested each background and foreground effect to see that it rendered as expected. We also have some unit testing on effects to make sure that a single frame looks as expected, which all passed.